

*****************************************
**********PROGRAMS NEEDED LATER**********
*****************************************

cap program drop aidstat
program define aidstat
cap replace gK_gni=gK_gni*100
cap replace gnipcrg=gnipcrg*100
cap replace totfullchg_gain=totfullchg_gain*100
foreach g in gni gdp {
	cap rename EearlyCpro_`g' earlyaidC_`g'
	cap replace earlyaidC_`g'=earlyaidC_`g'*100
	cap gen earlyaidC_`g'2=earlyaidC_`g'^2
	cap replace netoda_`g'=netoda_`g'*100
	cap gen netoda_`g'2=netoda_`g'^2
	cap replace repay_`g'=repay_`g'*100
	cap gen repay_`g'2=repay_`g'^2
}
end

cap program drop aidstatnoest
program define aidstatnoest
cap replace gK_gni=gK_gni*100
cap replace gnipcrg=gnipcrg*100
cap replace totfullchg_gain=totfullchg_gain*100
foreach g in gni gdp {
	cap rename earlyC_`g' earlyaidC_`g'
	cap replace earlyaidC_`g'=earlyaidC_`g'*100
	cap gen earlyaidC_`g'2=earlyaidC_`g'^2
	cap replace netoda_`g'=netoda_`g'*100
	cap gen netoda_`g'2=netoda_`g'^2
	cap replace repay_`g'=repay_`g'*100
	cap gen repay_`g'2=repay_`g'^2
}
end

cap program drop booneprep
program define booneprep
	sort country period
	by country: egen full=max(boone_full_country)
	replace full=full==1
	gen bsamp_full=full==1 & periodst>=1971 & periodst<=1991
	by country: egen base=max(boone_base_country)
	replace base=base==1
	gen bsamp_base=base==1 & periodst>=1971 & periodst<=1991
	
	replace lngni_relOECD=lngni_relOECDp
	replace lngni_relOECD2=lngni_relOECDp2
	replace popg=popg/100
	gen netoda_gni2=netoda_gni^2
	cap rename earlyC_gni earlyaidC_gni
	gen earlyaidC_gni2=earlyaidC_gni^2
	gen repay_gni2=repay_gni^2
	
	sort country periodst
	merge country periodst using "$DATA/boonefriendnet",nokeep
	drop _m
	
	tsset ccode period
end

cap program drop policyo
program define policyo
	cap drop policy_oldper
	cap drop policy_newper
	cap drop cons
	qui reg bdgdpg $bd bdsacw bdinfl bdbb $period if e(sample),r
	gen policy_oldper=bdsacw*_b[bdsacw]+bdinfl*_b[bdinfl]+bdbb*_b[bdbb] if e(sample)
	gen float cons=0
	format cons %20.18f
	foreach var in $bd $period {
		cap sum `var' if e(sample)
		cap replace cons=cons+r(mean)*_b[`var'] if e(sample)
	}
	replace cons=cons+_b[_cons] if e(sample)
	replace policy_oldper=policy_oldper+cons if e(sample)
end

cap program drop policyoiv
program define policyoiv
	cap drop policy_oldper
	cap drop policy_newper
	cap drop cons
	qui reg bdgdpg bdlgdp $bd bdsacw bdinfl bdbb $period if e(sample),r
	gen policy_oldper=bdsacw*_b[bdsacw]+bdinfl*_b[bdinfl]+bdbb*_b[bdbb] if e(sample)
	gen float cons=0
	format cons %20.18f
	foreach var in bdlgdp $bd $period {
		cap sum `var' if e(sample)
		cap replace cons=cons+r(mean)*_b[`var'] if e(sample)
		}
	replace cons=cons+_b[_cons] if e(sample)
	replace policy_oldper=policy_oldper+cons if e(sample)
end

cap program drop policyn
program define policyn
	cap drop policy_oldper
	cap drop policy_newper
	cap drop cons
	qui reg gdppcg $bd open_ww2 lninfl bbfinal $period if e(sample),r
	gen policy_newper=open_ww2*_b[open_ww2]+lninfl*_b[lninfl]+bbfinal*_b[bbfinal] if e(sample)
	gen float cons=0
	format cons %20.18f
	foreach var in $bd $period {
		cap sum `var' if e(sample)
		cap replace cons=cons+r(mean)*_b[`var'] if e(sample)
	}
	replace cons=cons+_b[_cons] if e(sample)
	replace policy_newper=policy_newper+cons if e(sample)
end
	
cap program drop policyniv
program define policyniv
	cap drop policy_oldper
	cap drop policy_newper
	cap drop cons
	qui reg gdppcg gdppc62_0 $bd open_ww2 lninfl bbfinal $period if e(sample),r
	gen policy_newper=open_ww2*_b[open_ww2]+lninfl*_b[lninfl]+bbfinal*_b[bbfinal] if e(sample)
	gen float cons=0
	format cons %20.18f
	foreach var in gdppc62_0 $bd $period {
		cap sum `var' if e(sample)
		cap replace cons=cons+r(mean)*_b[`var'] if e(sample)
	}
	replace cons=cons+_b[_cons] if e(sample)
	replace policy_newper=policy_newper+cons if e(sample)
end

cap program drop policyn62
program define policyn62
	cap drop policy_oldper
	cap drop policy_newper
	cap drop cons
	qui reg gdppcg62 $bd open_ww2 lninfl bbfinal $period if e(sample),r
	gen policy_newper=open_ww2*_b[open_ww2]+lninfl*_b[lninfl]+bbfinal*_b[bbfinal] if e(sample)
	gen float cons=0
	format cons %20.18f
	foreach var in $bd $period {
		cap sum `var' if e(sample)
		cap replace cons=cons+r(mean)*_b[`var'] if e(sample)
	}
	replace cons=cons+_b[_cons] if e(sample)
	replace policy_newper=policy_newper+cons if e(sample)
end

cap program drop policyn62iv
program define policyn62iv
	cap drop policy_oldper
	cap drop policy_newper
	cap drop cons
	qui reg gdppcg62 gdppc62_0 $bd open_ww2 lninfl bbfinal $period if e(sample),r
	gen policy_newper=open_ww2*_b[open_ww2]+lninfl*_b[lninfl]+bbfinal*_b[bbfinal] if e(sample)
	gen float cons=0
	format cons %20.18f
	foreach var in gdppc62_0 $bd $period {
		cap sum `var' if e(sample)
		cap replace cons=cons+r(mean)*_b[`var'] if e(sample)
	}
	replace cons=cons+_b[_cons] if e(sample)
	replace policy_newper=policy_newper+cons if e(sample)
end


cap program drop bdivgeno
program define bdivgeno
	cap drop bdarms1policy bdlgdppolicy bdlgdp2policy bdlpoppolicy bdlpop2policy
	gen bdarms1policy=bdarms1*policy_oldper
	gen bdlgdppolicy=bdlgdp*policy_oldper
	gen bdlgdp2policy=(bdlgdp^2)*policy_oldper
	gen bdlpoppolicy=bdlpop*policy_oldper
	gen bdlpop2policy=(bdlpop^2)*policy_oldper
end

cap program drop bdivgenold
program define bdivgenold
	foreach v in bdarms1policy bdlgdppolicy bdlgdp2policy bdlpoppolicy bdlpop2policy {
		cap drop `v'
	}
	gen bdarms1policy=bdarms1*policy_oldper
	gen bdlgdppolicy=bdlgdp*policy_oldper
	gen bdlgdp2policy=(bdlgdp^2)*policy_oldper
	gen bdlpoppolicy=bdlpop*policy_oldper
	gen bdlpop2policy=(bdlpop^2)*policy_oldper
end


cap program drop bdivgennew
program define bdivgennew
	foreach v in bdarms1policy bdlgdppolicy bdlgdp2policy bdlpoppolicy bdlpop2policy {
		cap drop `v'
	}
	gen bdarms1policy=bdarms1*policy_newper
	gen bdlgdppolicy=bdlgdp*policy_newper
	gen bdlgdp2policy=(bdlgdp^2)*policy_newper
	gen bdlpoppolicy=bdlpop*policy_newper
	gen bdlpop2policy=(bdlpop^2)*policy_newper
end



